package com.atguigu.educms.controller;


import com.atguigu.commonutils.R;
import com.atguigu.educms.entity.CrmBanner;
import com.atguigu.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import jdk.nashorn.internal.objects.annotations.Getter;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 * 管理员后台的banner接口
 * @author lsx
 * @since 2021-02-27
 */
@RestController
@RequestMapping("/educms/banneradmin")
@CrossOrigin
public class BannerAdminController {
    @Autowired
    private CrmBannerService bannerService;
    /**
     * 分页查询 两个参数
     *  page 当前页
     *  limit 每页的记录数
     */
    @GetMapping("pageBanner/{page}/{limit}")
    public  R PageBanner(@PathVariable long page,@PathVariable long limit){
        Page<CrmBanner> pageBanner = new Page<>(page,limit);
        bannerService.page(pageBanner,null);

        return R.ok().data("items",pageBanner.getRecords()).data("total",pageBanner.getTotal());
    }
    //根据id获取banner
    @GetMapping("getbanner/{id}")
    public  R getBannerById(@PathVariable String id){
        CrmBanner banner = bannerService.getById(id);
        return  R.ok().data("item",banner);
    }
    //新增
    @PostMapping("addBanner")
    public R addBanner(@RequestBody CrmBanner crmBanner){
        bannerService.save(crmBanner);
        return R.ok();
    }
    //修改
    @PostMapping("update")
    public  R updateBanner(@RequestBody CrmBanner crmBanner){
        bannerService.updateById(crmBanner);
        return  R.ok();
    }
    //删除
    @DeleteMapping("delete/{id}")
    public  R deleleBanner(@PathVariable String id){
        bannerService.removeById(id);
        return  R.ok();
    }
}

